package com.yqb.study.modular.controller.data;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yqb.study.common.controller.BaseController;
import com.yqb.study.common.mq.MqMessage;
import com.yqb.study.common.mq.MqSender;
import com.yqb.study.config.mq.MqConfig;
import com.yqb.study.util.ResultVoUtil;

import lombok.extern.slf4j.Slf4j;

// RestController返回json报文
@RestController
@Slf4j
@RequestMapping("/data")
public class MqController extends BaseController {

	@Autowired
	private MqSender mqSender;

	// 两个队列都收到消息,总共4条消息
	@GetMapping("/testMqFanout")
	private Object testMqFanout() {

		mqSender.sendFanout(new MqMessage(MqConfig.FANOUT_EXCHANGE, null, "往fanout.queue1中发送消息"));
		
		mqSender.sendFanout(new MqMessage(MqConfig.FANOUT_EXCHANGE, null, "往fanout.queue2中发送消息"));

		return ResultVoUtil.success();
	}	
	
	// 各队列只能收到自己规则对应的消息,总共2条消息
	@GetMapping("/testMqDirect")
	private Object testMqDirect() {

		mqSender.sendDirect(new MqMessage(MqConfig.DIRECT_EXCHANGE, MqConfig.DIRECT_QUEUE1_BIND_KEY, "往direct.queue1中发送消息"));
		
		mqSender.sendDirect(new MqMessage(MqConfig.DIRECT_EXCHANGE, MqConfig.DIRECT_QUEUE2_BIND_KEY, "往direct.queue2中发送消息"));

		return ResultVoUtil.success();
	}	

	// queue1只能收到1条消息,queue2能收到2条消息,总共收到3条消息
	@GetMapping("/testMqTopic")
	private Object testMqTopic() {

		mqSender.sendTopic(new MqMessage(MqConfig.TOPIC_EXCHANGE, MqConfig.TOPIC_QUEUE1_ROUTE_KEY_PREFIX + ".allqueue", "往topic.queue1中发送消息"));
		
		mqSender.sendTopic(new MqMessage(MqConfig.TOPIC_EXCHANGE, MqConfig.TOPIC_QUEUE2_ROUTE_KEY_PREFIX + ".justqueue2", "往topic.queue2中发送消息"));

		return ResultVoUtil.success();
	}
}
